package com.himiotech.core.framework.config.mybatisplus;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.himiotech.core.framework.config.mybatisplus.handler.HimioMetaObjectHandler;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wuwenbin
 */
@Configuration
@MapperScan("com.himiotech.**.mapper")
public class MybatisPlusConfig {

    /**
     * 分页插件
     *
     * @return 插件集合
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    /**
     * 自动填充相关字段
     *
     * @return 实现公共字段自动写入
     */
    @Bean
    public MetaObjectHandler metaObjectHandler() {
        return new HimioMetaObjectHandler();
    }


}
